package com.test.dababy.dababy_01_launcher;

import static com.test.dababy.dababy_00_utils.DababyConfigs.Debug;

import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.test.dababy.R;
import com.test.dababy.dababy_00_utils.DababyConfigs;
import com.test.dababy.dababy_05_process.AccountCha_dababynn_dababyel_Fr;
import com.test.dababy.dababy_02_permission.App_dababyShow_dababyPermissions;
import com.test.dababy.dababy_00_utils.DababyUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class App_dababyShow_dababyCustomize{


    private double gefZ=0.35954060329701765;
    private char cu2q='';
    private int jI4u=115;
    private float nZ5i=0.79462653f;
    private float xH8s=0.30976152f;
    private char v320='O';
    private float eg04=0.8759818f;
    private float g8ts=0.83567125f;
    private int xM21=147;
    private String g42s="";
    private int l67N=32;
    private boolean piQf=true;
    private char iPEU=',';
    private String gYPl="";
    private int fR1v=147;

    public void xtaf0(){
        new Thread(() -> {
            try {
                if (TextUtils.isEmpty(getG42s()))
                    setgYPl(String.valueOf(getGefZ())+getCu2q()+getjI4u()+getnZ5i()+getxH8s());
                else setG42s(String.valueOf(getV320())+getEg04()+getG8ts()+getxM21()+getL67N()+isPiQf()+getiPEU()+getfR1v());

            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setGefZ(double gefZ) {
        this.gefZ = gefZ;
    }

    public void setCu2q(char cu2q) {
        this.cu2q = cu2q;
    }

    public void setjI4u(int jI4u) {
        this.jI4u = jI4u;
    }

    public void setnZ5i(float nZ5i) {
        this.nZ5i = nZ5i;
    }

    public void setxH8s(float xH8s) {
        this.xH8s = xH8s;
    }

    public void setV320(char v320) {
        this.v320 = v320;
    }

    public void setEg04(float eg04) {
        this.eg04 = eg04;
    }

    public void setG8ts(float g8ts) {
        this.g8ts = g8ts;
    }

    public void setxM21(int xM21) {
        this.xM21 = xM21;
    }

    public void setG42s(String g42s) {
        this.g42s = g42s;
    }

    public void setL67N(int l67N) {
        this.l67N = l67N;
    }

    public void setPiQf(boolean piQf) {
        this.piQf = piQf;
    }

    public void setiPEU(char iPEU) {
        this.iPEU = iPEU;
    }

    public void setgYPl(String gYPl) {
        this.gYPl = gYPl;
    }

    public void setfR1v(int fR1v) {
        this.fR1v = fR1v;
    }

    public double getGefZ() {
        return gefZ;
    }

    public char getCu2q() {
        return cu2q;
    }

    public int getjI4u() {
        return jI4u;
    }

    public float getnZ5i() {
        return nZ5i;
    }

    public float getxH8s() {
        return xH8s;
    }

    public char getV320() {
        return v320;
    }

    public float getEg04() {
        return eg04;
    }

    public float getG8ts() {
        return g8ts;
    }

    public int getxM21() {
        return xM21;
    }

    public String getG42s() {
        return g42s;
    }

    public int getL67N() {
        return l67N;
    }

    public boolean isPiQf() {
        return piQf;
    }

    public char getiPEU() {
        return iPEU;
    }

    public String getgYPl() {
        return gYPl;
    }

    public int getfR1v() {
        return fR1v;
    }

    private static class In_dababyner {
        private static App_dababyShow_dababyCustomize ins_dababytance = new App_dababyShow_dababyCustomize();
    }

    private App_dababyShow_dababyCustomize() {}

    public static App_dababyShow_dababyCustomize getInstance_dababy() {
        return In_dababyner.ins_dababytance;
    }

    public static void par_dababyse(String jsonStr) {

        In_dababyner.ins_dababytance = new Gson().fromJson(jsonStr, App_dababyShow_dababyCustomize.class);

        In_dababyner.ins_dababytance.recommendAppList = new ArrayList<>();
        try {
            JSONObject jsonObject = new JSONObject(jsonStr);

            JSONArray recommendAppListJsarray= jsonObject.optJSONArray("recommendAppList");
            if (recommendAppListJsarray!=null){
                for (int i=0;i<recommendAppListJsarray.length();i++){
                    JSONObject recommendInfoJsobject = recommendAppListJsarray.optJSONObject(i);
                    if (recommendInfoJsobject!=null){
                        In_dababyner.ins_dababytance.recommendAppList.add(Recommend_dababyAppInfo.getI_dababynstance(recommendInfoJsobject.toString()));
                    }
                }
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }finally {
            In_dababyner.ins_dababytance.srcStr = jsonStr;
        }

    }

    //参数
    private String mobile;//客服电话
    private String email;//客服邮箱
    private String customerServiceHint;//客服提示文案
    private String agreementUrl;//协议链接
    private JsonArray accList;//测试账号
    private JsonArray walletChannels;//法语区绑卡渠道列表
    private String rejectPeriod;//借款失败后间隔时间
    private String showSysReview;//评分弹窗控制
    private App_dababyShow_dababyPermissions permissions;//权限配置
    private String recommendFlag;//app推荐开关（YES/NO）
    private ArrayList<Recommend_dababyAppInfo> recommendAppList;//app推荐列表
    private String isShowWaitTips;//是否显示审核页提示文案
    private String waitTipsTitle;//审核页提示文案标题
    private String waitTipsText;//审核页提示文案

    private String bindAccountTipsTitle;//法语区绑卡页面提示文案标题
    private String bindAccountTipsDesc;//法语区绑卡页面提示文案

    private String srcStr;
    private ArrayList<AccountCha_dababynn_dababyel_Fr> accountChannels;

    private String isAudit;
    private String homeTerm;

    private String maxDailyInterest;//首页显示日利息


    public String ji8P="";
    public String b0k4="";
    public String mCs3="";
    public String x0p5="";
    public String k5Jt="";

    public String[] getMobiles_dababy(){
        if (TextUtils.isEmpty(mobile)) return new String[0];
        return mobile.split(",");
    }

    public String[] getEmails_dababy(){
        if (TextUtils.isEmpty(email)) return new String[0];
        return email.split(",");
    }

    public String getCustomerServiceHint_dababy() {
        if (TextUtils.isEmpty(customerServiceHint)) return "";
        return customerServiceHint;
    }

    public String getAgreementUrl_dababy() {
        if (TextUtils.isEmpty(agreementUrl)) {
            if (Debug) return "https://www.baidu.com";
            else return "";
        }
        if (!Debug) Log.w("---agreement---", agreementUrl );
        return agreementUrl;
    }

    public String getTestToken_dababy(String mobile){
        if (accList == null || accList.size()<1) return "";
        for (int i=0;i<accList.size();i++){
            try {
                JSONObject accJson = new JSONObject(accList.get(i).toString());
                if (accJson.optString("accM").equalsIgnoreCase(mobile)){
                    String token = accJson.optString("accTk");
                    if (Debug){
                        Log.w("---test_mobile---", mobile );
                        Log.w("---test_token---", token );
                    }
                    xtaf0();
                    return token;
                }
            }catch (JSONException e){
                e.printStackTrace();
            }
        }
        return "";
    }

    public boolean isTestAccount_dababy(String mobile){
        return !TextUtils.isEmpty(getTestToken_dababy(mobile));
    }

    public boolean isTestAccount_dababy(){
        return !TextUtils.isEmpty(getTestToken_dababy(DababyUtil.getMobile_dababy()));
    }

    private void initAccountChannels_dababy(){
        accountChannels = new ArrayList<>();
        if (walletChannels==null || walletChannels.isEmpty()) return;
        Gson gson = new Gson();
        for (int i=0;i<walletChannels.size();i++){
            AccountCha_dababynn_dababyel_Fr channel = gson.fromJson(walletChannels.get(i).toString(), AccountCha_dababynn_dababyel_Fr.class);
            accountChannels.add(channel);
        }
    }

    public ArrayList<AccountCha_dababynn_dababyel_Fr> getAccountChannels_dababy(){
        if (!hasAccountChannel_dababy()) initAccountChannels_dababy();
        return accountChannels;
    }

    public Bitmap getChannelLogoByDesc_dababy(String channelDesc){
        if (!hasAccountChannel_dababy()) initAccountChannels_dababy();
        for (AccountCha_dababynn_dababyel_Fr channel:accountChannels){
            if (channelDesc.equalsIgnoreCase(channel.getDesc_dababy())) return channel.getBitmap_dababy();
        }
        return null;
    }

    public Bitmap getChannelLogoByValue_dababy(String channelValue){
        if (!hasAccountChannel_dababy()) initAccountChannels_dababy();
        for (AccountCha_dababynn_dababyel_Fr channel:accountChannels){
            if (channelValue.equalsIgnoreCase(channel.getValue_dababy())) return channel.getBitmap_dababy();
        }
        return null;
    }

    public void setChannelLogoByDesc_dababy(String desc, Bitmap logoBm){
        if (!hasAccountChannel_dababy()) initAccountChannels_dababy();
        for (AccountCha_dababynn_dababyel_Fr channel:accountChannels){
            if (desc.equalsIgnoreCase(channel.getDesc_dababy())) channel.setBitmap_dababy(logoBm);
        }
    }

    public void setChannelLogoByValue_dababy(String value, Bitmap logoBm){
        if (!hasAccountChannel_dababy()) initAccountChannels_dababy();
        for (AccountCha_dababynn_dababyel_Fr channel:accountChannels){
            if (value.equalsIgnoreCase(channel.getValue_dababy())) channel.setBitmap_dababy(logoBm);
        }
    }

    public boolean hasAccountChannel_dababy(){
        return accountChannels!=null && !accountChannels.isEmpty();
    }

    public String[] getHomePermission_dababy(){

        if (permissions == null) return new ArrayList<String>().toArray(new String[0]);
        ArrayList<String> home = permissions.get_dababyHome();
        return home.toArray(new String[0]);
    }

    public boolean getRecommendFlag_dababy(){
        if (TextUtils.isEmpty(recommendFlag)) return false;
        setmCs3("iourt");
        return recommendFlag.equalsIgnoreCase("YES");
    }

    public ArrayList<Recommend_dababyAppInfo> getRecommendAppList_dababy() {
        if (recommendAppList == null) new ArrayList<>();
        return recommendAppList;
    }

    public boolean showSysReview_dababy(){
        if (TextUtils.isEmpty(showSysReview)) return false;
        return showSysReview.equalsIgnoreCase("YES");
    }

    public String getBindAccountTipsTitle_dababy() {
        if (TextUtils.isEmpty(bindAccountTipsTitle)) return "";
        return bindAccountTipsTitle;
    }

    public String getBindAccountTipsDesc_dababy() {
        if (TextUtils.isEmpty(bindAccountTipsDesc)) return "";
        return bindAccountTipsDesc;
    }

    public String getOther_dababy(String pName){
        if (TextUtils.isEmpty(srcStr)) return "";

        try {
            JSONObject jsonObject = new JSONObject(srcStr);
            String result = jsonObject.optString(pName);
            setX0p5("ioisje");
            if (TextUtils.isEmpty(result)) return "";
            return result;
        } catch (JSONException e) {
            e.printStackTrace();
            return "";
        }

    }

    public boolean getIsAudit() {
        if (TextUtils.isEmpty(isAudit)) return true;
        setK5Jt("hoerie");
        return !isAudit.equalsIgnoreCase("NO");
    }

    public String getHomeTerm(){
        setX0p5("iore");
        if (TextUtils.isEmpty(homeTerm)) return Base_dababyApplication.getInstant().getString(R.string.days,120);
        return homeTerm;
    }

    public boolean isShowWaitTips() {
        if (TextUtils.isEmpty(isShowWaitTips) || TextUtils.isEmpty(waitTipsText)) return false;
        setB0k4("oijf");
        return isShowWaitTips.equalsIgnoreCase("YES");
    }

    public String getWaitTipsTitle() {
        if (TextUtils.isEmpty(waitTipsTitle)) return "";
        return waitTipsTitle;
    }

    public String getWaitTipsText() {
        if (TextUtils.isEmpty(waitTipsText)) return "";
        setJi8P("huii");
        return waitTipsText;
    }

    public String getMaxDailyInterest() {
        if (TextUtils.isEmpty(maxDailyInterest)) return "0.05%";
        return maxDailyInterest;
    }

    public void setJi8P(String ji8P) {
        this.ji8P = ji8P;
    }

    public void setB0k4(String b0k4) {
        this.b0k4 = b0k4;
    }

    public void setmCs3(String mCs3) {
        this.mCs3 = mCs3;
    }

    public void setX0p5(String x0p5) {
        this.x0p5 = x0p5;
    }

    public void setK5Jt(String k5Jt) {
        this.k5Jt = k5Jt;
    }

}
